﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Tools;

namespace Punia
{
    [CommandAttribute(true)]
    public partial class drop_contract : BaseForm
    {
        public drop_contract()
            : base()
        {
        }

        public drop_contract(DbContext dbContext)
            :base(dbContext)
        {
            InitializeComponent();

            cbContract.DataSource = Utility.contracts_select(dbContext);
            cbContract.DisplayMember = "Name";

            cbContract.SelectedIndexChanged += new EventHandler(cbContract_SelectedIndexChanged);
        }

        void cbContract_SelectedIndexChanged(object sender, EventArgs e)
        {
            Write();
        }

        protected override void Write()
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("USE [" + dbContext.Database + "];");
            sb.AppendLine();
            if (cbContract.SelectedIndex > 0)
            {
                sb.Append("DROP CONTRACT [" + cbContract.Text + "]");
            }

            tbCommand.Text = sb.ToString();
        }
    }
}